<#--
@author：linsir
@date ：Created in 2021/7/22 9:25
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>职务xxxx</legend>
        </fieldset>
    </div>
    <form id="metaObject" class="layui-form" action="" method="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">真实姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="position" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">xxxx</label>
                <div class="layui-input-inline">
                    <input type="text" name="description" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-inline">
                    <input id="sel" type="text" name="pos" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="position"  >立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>
</div>
<script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/layuimini/js/lay-config.js" charset="utf-8"></script>


<script>
    layui.use(['form','jquery','customSelect','treetable'],function () {
        var form = layui.form,
            layer = layui.layer,
            customSelect=layui.customSelect;
        form.render();

        $.ajax({
            type:'get',
            url:'/organ/tree',
            dataType:'json',
            success:function (res)
            {
                customSelect.render({
                    el: 'sel',
                    data: res,
                    checkbox: true,
                    checked: function (obj) {
                        console.log(obj)
                        //obj.value 已选数据的title
                        //obj.data 已选数据
                    }
                }) ;
            }
        });


        form.on('submit(position)',function (data) {
            $.ajax({
                type:'post',
                url:'/position/add',
                data:data.field,  //重点必须为一个变量如：data
                dataType:'json',
                success:function(res){
                    //layer.alert(JSON.stringify(res));

                    var index = layer.alert(JSON.stringify(res), {
                        title: '最终的提交信息'
                    });

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.location.reload();
                    parent.layer.close(iframeIndex);

                },
                error:function(){
                    layer.alert(JSON.stringify('失败'));
                }
            });
            return false;
        });

    });
</script>

</body>
</html>